//
// Created by hunan on 25-7-13.
//

#ifndef DOWNLOAD_FRAGMENT_H
#define DOWNLOAD_FRAGMENT_H

#include <cstdint>
#include <map>
#include <string>

class DownloadFragment
{
public:
    enum EmFragmentStatus
    {
        EmInit = 0,
        EmUsed,
        EmDone,
        EmUnUsed,
        EmFailed,
    };
    struct Fragment
    {
        int m_min{};
        int m_max{};
        int m_size{};
        int m_status{EmInit};
    };
public:
    explicit DownloadFragment(uint64_t data_size, int fragment_size = 10240);// 10KB
    void FragmentDataSize();
    int  RemoveLocalFragment(uint64_t data_size);
    bool IsFragmentDataSize() const;
    bool GetOneFragment(int & min, int & max);
    void Update(int min, int max, int status);
    int  IsGetFragmentAll() const;
private:
    uint64_t m_data_size{};
    int m_fragment_size{};
    std::map<int, Fragment> m_fragments{};
};



#endif //DOWNLOAD_FRAGMENT_H
